home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Controls / Visual Basic Controls.iso / vbcontrol / cstwnd / ccheck.cpp < prev    next >
C/C++ Source or Header  |  1993-12-17  |  3KB  |  99 lines

  1. #include "custctl.h"
  2. #include "cCheck.h"
  3. #include <edit.h>
  4. #include <bstatic.h>
  5. #include <windowsx.h>
  6.  
  7. char CCheckClassName[]  = "CCHECK";   // class for new custom control
  8.  
  9. #include "ctlids.h"
  10.  
  11. /*******************************************************************
  12. TCRadio - A New radio button class.
  13. *******************************************************************/
  14. TCCheck::TCCheck(PTWindowsObject AParent, int AnId,
  15.     LPSTR ATitle, int X, int Y, int W, int H,
  16.     PTModule AModule)
  17.     : TStateButton(AParent, AnId, ATitle, X, Y, W, H,
  18.         AModule)
  19. {
  20.     On = LoadBitmap(DLLModule->hInstance, "CCHECK_ON_BMP");
  21.    Off = LoadBitmap(DLLModule->hInstance, "CCHECK_OFF_BMP");
  22.     Mask = LoadBitmap(DLLModule->hInstance, "CCHECK_MASK_BMP");
  23. }
  24.  
  25. TCCheck::TCCheck(PTWindowsObject AParent, int ResourceId,
  26.     PTModule AModule)
  27.     : TStateButton(AParent, ResourceId, AModule)
  28. {
  29.     On = LoadBitmap(DLLModule->hInstance, "CCHECK_ON_BMP");
  30.     Off = LoadBitmap(DLLModule->hInstance, "CCHECK_OFF_BMP");
  31.     Mask = LoadBitmap(DLLModule->hInstance, "CCHECK_MASK_BMP");
  32. }
  33.  
  34. TCCheck::~TCCheck()
  35. {
  36.     DeleteObject(On);
  37.    DeleteObject(Off);
  38.     DeleteObject(Mask);
  39. }
  40.  
  41. LPSTR TCCheck::GetClassName()
  42. {
  43.     return CCheckClassName;
  44. }
  45.  
  46. void TCCheck::DrawOn(HDC DrawDC)
  47. {
  48.     HDC CopyDC = CreateCompatibleDC(DrawDC);
  49.     HBITMAP Old = SelectBitmap(CopyDC, Mask);
  50.  
  51.     BitBlt(DrawDC, 0, 0, 20, 20, CopyDC, 0, 0, SRCAND);
  52.  
  53.     SelectBitmap(CopyDC, On);
  54.  
  55.     BitBlt(DrawDC, 0, 0, 20, 20, CopyDC, 0, 0, SRCINVERT);
  56.  
  57.     SetBkMode(DrawDC, TRANSPARENT);
  58.     SendMessage(Parent->HWindow, WM_CTLCOLOR,
  59.         (WPARAM)DrawDC, MAKELPARAM(HWindow,
  60.         CTLCOLOR_STATIC));
  61.  
  62.     char Text[80];
  63.     GetWindowText(HWindow, Text, 80);
  64.     TextOut(DrawDC, 22, 2, Text, lstrlen(Text));
  65.  
  66.    SelectBitmap(CopyDC, Old);
  67.    DeleteDC(CopyDC);
  68. }
  69.  
  70. void TCCheck::DrawOff(HDC DrawDC)
  71. {
  72.     HDC CopyDC = CreateCompatibleDC(DrawDC);
  73.     HBITMAP Old = SelectBitmap(CopyDC, Mask);
  74.  
  75.     BitBlt(DrawDC, 0, 0, 20, 20, CopyDC, 0, 0, SRCAND);
  76.                                         
  77.     SelectBitmap(CopyDC, Off);
  78.  
  79.     BitBlt(DrawDC, 0, 0, 20, 20, CopyDC, 0, 0, SRCINVERT);
  80.  
  81.     SetBkMode(DrawDC, TRANSPARENT);
  82.     SendMessage(Parent->HWindow, WM_CTLCOLOR,
  83.         (WPARAM)DrawDC, MAKELPARAM(HWindow,
  84.         CTLCOLOR_STATIC));
  85.  
  86.     char Text[80];
  87.     GetWindowText(HWindow, Text, 80);
  88.     TextOut(DrawDC, 22, 2, Text, lstrlen(Text));
  89.  
  90.    SelectBitmap(CopyDC, Old);
  91.    DeleteDC(CopyDC);
  92. }
  93.  
  94. void TCCheck::GetWindowClass(WNDCLASS _FAR& WndClass)
  95. {
  96.     TStateButton::GetWindowClass(WndClass);
  97.  
  98.     WndClass.hbrBackground = NULL;
  99. }